<template>
    <div id="myChart" :style="{width: '700px', height: '600px'}"></div>
</template>
<script>

    import axios from 'axios'
    export default {
        name: 'Echarts',
        mounted(){
            let _this=this

            axios.get('http://localhost:8888/num').then(function (response) {
                // 基于准备好的dom，初始化echarts实例
                let myChart = _this.$echarts.init(document.getElementById('myChart'))
                // 绘制图表
                myChart.setOption({
                    title: {
                        text: '播放量破千万、破亿数量对比',
                        subtext: '数据来自bilibili'
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow'
                        }
                    },
                    legend: {
                        data: ['番剧', '国产动画']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'value',
                        boundaryGap: [0, 0.01]
                    },
                    yAxis: {
                        type: 'category',
                        data: ['播放量破千万数量', '播放量破亿数量']
                    },
                    series: [
                        {
                            name: '番剧',
                            type: 'bar',
                            data: response.data.riMilionBilion
                        },
                        {
                            name: '国产动画',
                            type: 'bar',
                            data: response.data.guoMilionBilion
                        }
                    ]
                });
            })

        }
    }
</script>